<?php

namespace app\index\controller;


use org\Sitemap;
use Yunpian\Sdk\YunpianClient;

class Index extends Base
{

    public function sns()
    {
        //初始化client,apikey作为所有请求的默认值
        $clnt = @YunpianClient::create();

        $param = [YunpianClient::MOBILE => '18616020000', YunpianClient::TEXT => '【云片网】您的验证码是1234'];
        $r = $clnt->sms()->single_send($param);
        dump($clnt->user());
        if ($r->isSucc()) {
            //$r->data()
        }
    }

    //新版
    public function index($navid = null)
    {
        $date = array();
        $date['link'] = db('link')->field('title,url')
            ->where($this->datas)
            ->limit(16)->cache(true)->select();

        $date['ucase'] = db('ucase')->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.*,c.name')
            ->where('a.status', '1')
            ->where('a.lang', cookie('think_var'))
            ->order('a.sort DESC,a.id DESC')
            ->cache(true)
            ->limit(9)
            ->select();

        $date['Article'] = db('Article')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.miaoshu,a.issue,a.title,a.image,a.cid,c.name,c.create_time')
            ->where('a.status', '1')
            ->where('a.lang', cookie('think_var'))
            ->order('a.sort DESC,a.id DESC')
            ->cache(true)
            ->limit(9)
            ->select();

        /**
         * 华铭
         */
        $date['product'] = cache('product' . cookie('think_var'));
        if (empty($date['product'])) {
            $product1 = db('nav')
                ->field('name,id,model')
                ->where('status', '1')
                ->where('grade', '1')
                ->where('lang', cookie('think_var'))
                // ->cache(true)
                ->order('sort DESC')
                ->select();
            foreach ($product1 as $key => $value) {
                $product1[$key]['children'] = db('product')
                    ->field('title,id,cid,image,icon')
                    ->where('cid', $value['id'])
                    ->where('status', '1')
                    ->where('lang', cookie('think_var'))
                    ->order('sort DESC')
                    // ->cache(true)
                    ->limit(8)
                    ->select();
                if (empty($product1[$key]['children'])) {
                    unset($product1[$key]);
                }
            }

            $product2 = db('nav')
                ->field('c.id,s.id,s.name,s.pid')
                ->alias('c')
                ->join('__NAV__ s', 's.pid = c.id', 'right ')
                ->where('s.model', 'product')
                ->where('c.lang', cookie('think_var'))
                ->where('s.grade', '2')
                ->group('c.id')
                ->column('c.id,c.name,c.model');
            foreach ($product2 as $key => $value) {
                $d = db('nav')->where('pid', $key)->column('id');
                $keya = null;
                foreach ($d as $key2) {
                    $keya .=  $key2 . ',';
                }
                $keya .=  $key2;
                $product2[$key]['children'] = db('product')
                    ->field('title,id,cid,image,icon')
                    ->where('cid', 'in', $keya)
                    ->where('status', '1')
                    ->where('lang', cookie('think_var'))
                    ->order('sort DESC')
                    // ->cache(true)
                    ->limit(8)
                    ->select();
            }

            $product = array_merge($product1, $product2);
            $date['product'] = cache('product' . cookie('think_var'), $product);
        }

        $date['product'] = db('product')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.miaoshu,a.issue,a.title,a.image,a.cid,c.name,c.create_time')
            ->where('a.status', '1')
            ->where('a.lang', cookie('think_var'))
            ->order('a.sort DESC,a.id DESC')
            ->cache(true)
            ->limit(9)
            ->select();

        $this->assign('date', $date);
        return $this->fetch($this->template . 'index.html');
    }


    /**
     * @return mixed|void军区定制
     */
    public function indexSS($navid = null)
    {
        //友情链接
        $link = cache('link' . cookie('think_var'));
        if (empty($link_junqu)) {
            $link['one'] = model('link')->where('lang', 1)
                ->order('sort desc,create_time Asc')
                //                ->limit(4)
                ->select();
            $link['two'] = model('link')->where('lang', 2)
                ->order('sort desc,create_time Asc')
                //                ->limit(5)
                ->select();
            $link['tree'] = model('link')->where('lang', 3)
                ->order('sort desc,create_time Asc')
                //                ->limit(6)
                ->select();
            cache('link' . cookie('think_var'), $link);
        }

        //视屏广告连接
        $adindex = model('adindex')->where($this->datas)->column('url,title,image', 'position');

        //军事头条
        $top = model('article')
            ->field('id,title,cid')
            ->where('status', '1')
            ->order('sort DESC')
            ->where('top', 1)
            ->limit(4)->select();

        //最新新闻轮播
        $Article['img'] = db('article')
            ->field('title,id,cid,miaoshu,image')
            ->where('status', '1')
            ->where('cid', '313')
            ->where('image', '<>', '')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(5)
            ->select();

        $danweilist = model('company')->where('status', 1)->order('sort desc')->select();
        foreach ($danweilist as $key => $value) {
            $danweilist[$key]['list'] = db('article')
                ->field('title,id,cid,miaoshu,image')
                ->where('status', '1')
                ->where('comid', $value['id'])
                ->where('lang', cookie('think_var'))
                ->order('sort DESC,create_time DESC')
                ->limit(11)
                ->select();
        }
        //单位
        $danwei = model('company')
            ->where('status', 1)
            ->order('passnum DESC,allnum DESC')
            ->limit(10)
            ->select();
        foreach ($danwei as $key => $value) {

            //投稿数
            $danwei[$key]['listall'] = db('article')
                ->where('comid', $value['id'])
                ->where('contribute', '1')
                ->count();
            //采用数
            $danwei[$key]['listnum'] = db('article')
                ->where('status', '1')
                ->where('contribute', '1')
                ->where('comid', $value['id'])
                ->count();
            //            if (empty($danwei[$key]['list'])) {
            //                unset($danwei[$key]);
            //            }
        }
        //
        //
        //        $aa['all']= db('article')
        //            ->alias('c')
        //            ->field('c.title,c.id,a.title as atitle,c.comid,count(c.comid) as numall')
        //            ->join('__COMPANY__ a', 'a.id= c.comid')
        //            ->where('c.status', '1')
        //            ->where('c.contribute', '1')
        //            ->where('c.lang', cookie('think_var'))
        //            ->group('a.title')
        //            ->order('numall desc')
        //           ->select();
        //
        //        $aa['num']= db('article')
        //            ->alias('c')
        //            ->field('c.title,c.id,a.title as atitle,c.comid,count(c.comid) as num')
        //            ->join('__COMPANY__ a', 'a.id= c.comid')
        //            ->where('c.contribute', '1')
        //            ->where('c.lang', cookie('think_var'))
        //            ->group('a.title')
        //            ->order('num desc')
        //           ->select();
        //
        //dump($aa);
        //dump($danwei);
        //新闻动态
        $Article['f'] = cache('Article' . cookie('think_var'));
        if (empty($Article['f'])) {
            $Article['f'] = db('Article')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.id,a.miaoshu,a.issue,a.title,a.image,a.cid,c.name,c.create_time')
                ->where('a.status', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('Article' . cookie('think_var'), $Article['f']);
        }

        //流沙要闻
        $Article['yaowen'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '313')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(12)
            ->select();

        //事实新闻
        $Article['shishi'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '314')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(12)
            ->select();

        //参谋部
        $Article['canmu'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '346')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(11)
            ->select();

        //政治工作处
        $Article['zhengzhi'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '347')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(11)
            ->select();

        //岸勤处
        $Article['anqing'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '348')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(11)
            ->select();

        //政策法规
        $Article['fagui'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            //原版            ->where('cid', '393')
            ->where('cid', '394')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(4)
            ->select();

        //通共公告
        $Article['gonggao'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            //原版            ->where('cid', '394')
            ->where('cid', '393')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(4)
            ->select();

        //强军思想
        $Article['sixiang'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '349')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //党的建设
        $Article['jianshe'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '350')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //宣传教育
        $Article['xuanchuang'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '351')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //政工研究
        $Article['yanjiu'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '352')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(21)
            ->select();

        //扫雷装备
        $Article['zhuangbei'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '354')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //水雷信息
        $Article['shuilei'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '355')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //世界海军水雷发展史
        $Article['shijie'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '356')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //扫雷史
        $Article['saolei'] = db('Article')
            ->field('id,miaoshu,issue,title,image,cid')
            ->where('status', '1')
            ->where('cid', '357')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //互动交流，领导信箱
        $Article['mailbox'] = db('user')
            ->where('status', '1')
            //->where('cid', '1')
            ->where('type', '1')
            ->where('position', 'neq', '0')
            ->where('lang', cookie('think_var'))
            ->column('*', 'position');
        //dump( $Article['mailbox']);
        //exit();

        //流沙论坛
        $Article['bbs'] = db('bbs')
            ->field('id,title,miaoshu,image')
            ->where('status', '1')
            //->where('cid', '1')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,create_time DESC')
            ->limit(9)
            ->select();

        //问卷调查
        $Article['wenjuan'] = db('research')
            ->field('id,title,cid')
            ->where('status', '1')
            //->where('cid', '1')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(10)
            ->select();

        //热门电影
        $Article['dianying'] = db('download')
            ->field('id,miaoshu,image,issue,title,cid')
            ->where('status', '1')
            ->where('cid', '363')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(13)
            ->select();

        //书籍
        $Article['shuji'] = db('download')
            ->field('id,miaoshu,image,issue,title,cid')
            ->where('status', '1')
            ->where('cid', '364')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(10)
            ->select();

        //音乐
        $Article['yingyue'] = db('download')
            ->field('id,miaoshu,image,issue,title,cid')
            ->where('status', '1')
            ->where('cid', '365')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(9)
            ->select();

        //游戏
        $Article['youxi'] = db('download')
            ->field('id,miaoshu,image,issue,title,cid')
            ->where('status', '1')
            ->where('cid', '366')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(9)
            ->select();

        //软件
        $Article['ruanjian'] = db('download')
            ->field('id,miaoshu,issue,title,cid')
            ->where('status', '1')
            ->where('cid', '367')
            ->where('lang', cookie('think_var'))
            ->order('sort DESC,update_time DESC')
            ->limit(11)
            ->select();

        $this->assign([
            'link' => $link,
            'Article' => $Article,
            'top' => $top,
            'danwei' => $danwei,
            'danweilist' => $danweilist,
            //            'product_nav' => $product_nav,
        ]);
        return $this->fetch($this->template . 'index.html');
    }


    //普通的首页_旧版
    public function index_old($navid = null)
    {
        /*
         * 商品栏目
         *
         *
        $product_nav = cache('product_nav' . cookie('think_var'));
        if (empty($product_nav)) {
            $product_nav = db('product_nav')
                ->where('status', '1')
                ->select();
            foreach ($product_nav as $key => $value) {
                $value['type'] = trim($value['type'], ",");
                $ayy = explode(',', $value['type']);
                $o = array_filter($ayy);
                $product_nav[$key]['ling'] =array();
                foreach ($o as $keyy => $valuee) {
                    $product_nav[$key]['ling'][$keyy]['fname'] = db('nav')->where('id', $valuee)->value('name','id');
                    $product_nav[$key]['ling'][$keyy]['id'] =$valuee;
                    $product_nav[$key]['ling'][$keyy]['fname_nav'] = db('nav')
                        ->where('pid', $valuee)
                        ->where('model', 'Product')
                        ->where('status', '1')
                        ->order('sort desc')
                        ->select();
                }
            }
            cache('product_nav' . cookie('think_var'), $product_nav);
        }
        */



        //友情链接
        $link = cache('link' . cookie('think_var'));
        if (empty($link)) {
            $link = model('link')->where($this->datas)->limit(16)->select();
            cache('link' . cookie('think_var'), $link);
        }


        //案例
        $ucase = cache('ucase' . cookie('think_var'));
        if (empty($ucase)) {
            $ucase = db('ucase')->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('ucase' . cookie('think_var'), $ucase);
        }

        //推荐产品
        $product = cache('product' . cookie('think_var'));
        if (empty($product)) {
            $product = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('product' . cookie('think_var'), $product);
        }

        //热销产品
        $producthot = cache('producthot' . cookie('think_var'));
        if (empty($producthot)) {
            $producthot = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.hot', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('producthot' . cookie('think_var'), $producthot);
        }

        //产品分类显示
        $product1 = cache('product1' . cookie('think_var'));
        if (empty($product1)) {
            $product1 = db('nav')
                ->field('name,id,model')
                ->where('status', '1')
                ->where('pid', 'neq', '0')
                ->where('model', 'Product')
                ->where('lang', cookie('think_var'))
                ->order('sort DESC')
                ->select();

            foreach ($product1 as $key => $value) {
                $product1[$key]['list'] = db('product')
                    ->field('title,id,cid,miaoshu,image')
                    ->where('cid', $value['id'])
                    ->where('status', '1')
                    ->where('lang', cookie('think_var'))
                    ->order('sort DESC')
                    ->limit(10)
                    ->select();
                if (empty($product1[$key]['list'])) {
                    unset($product1[$key]);
                }
            }
            cache('product1' . cookie('think_var'), $product1);
        }

        if (cookie('think_var') == 'zh-cn') {
            //水壶
            $product['shuihu'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '304')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //西施煲
            $product['xishi'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '307')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //连体锅
            $product['lianti'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '306')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //大锅
            $product['shangyong'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '305')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
        } else {
            //水壶
            $product['shuihu'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '328')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //西施煲
            $product['xishi'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '331')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //连体锅
            $product['lianti'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '329   ')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            //大锅
            $product['shangyong'] = db('product')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.cid', '330')
                ->where('a.tuijian', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
        }

        //新闻动态
        $Article = cache('Article' . cookie('think_var'));
        if (empty($Article)) {
            $Article = db('Article')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.id,a.miaoshu,a.issue,a.title,a.image,a.cid,c.name,c.create_time')
                ->where('a.status', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('Article' . cookie('think_var'), $Article);
        }

        //信息学堂
        $classroom = cache('classroom' . cookie('think_var'));
        if (empty($classroom)) {
            $classroom = db('classroom')
                ->alias('a')
                ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
                ->field('a.*,c.name')
                ->where('a.status', '1')
                ->where('a.lang', cookie('think_var'))
                ->order('a.sort DESC,a.id DESC')
                ->limit(8)
                ->select();
            cache('classroom' . cookie('think_var'), $classroom);
        }

        $this->assign([
            'link' => $link,
            'ucase' => $ucase,
            'product' => $product,
            'producthot' => $producthot,
            'classroom' => $classroom,
            'product1' => $product1,
            'Article' => $Article,
            //            'product_nav' => $product_nav,
        ]);
        return $this->fetch($this->template . 'index.html');
    }

    public function right()
    {
        return true;
    }

    public function lang()
    {
        switch ($this->request->param('lang')) {
            case 'en':
                cookie('think_var', 'en-us');
                break;
            case 'cn':
            default:
                cookie('think_var', 'zh-cn');
                break;
                //其它语言
        }
        //        $this->redirect($this->request->server('HTTP_REFERER'));
    }

    public function setmap()
    {
        $Article = db('Article')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.cid,c.model,a.create_time')
            ->where('a.status', '1')
            ->order('a.sort DESC,a.id DESC')
            ->select();
        $classroom = db('classroom')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.cid,c.model,a.create_time')
            ->where('a.status', '1')
            ->order('a.sort DESC,a.id DESC')
            ->select();
        $nav = db('nav')
            ->field('id,model,create_time')
            ->where('status', '1')
            ->where('model', 'about')
            ->order('sort DESC,id DESC')
            ->select();
        $product = db('product')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.cid,c.model,a.create_time')
            ->where('a.status', '1')
            ->order('a.sort DESC,a.id DESC')
            ->select();
        $ucase = db('ucase')
            ->alias('a')
            ->join('__NAV__ c', 'c.id= a.cid AND c.lang= a.lang AND c.status = a.status')
            ->field('a.id,a.cid,c.model,a.create_time')
            ->where('a.status', '1')
            ->order('a.sort DESC,a.id DESC')
            ->select();
        $all = array_merge($Article, $classroom, $product, $ucase, $nav);
        $site = new Sitemap();
        foreach ($all as $v) {
            if (empty($v['cid'])) {
                $dd['url'] = $this->request->domain() . url($v['model'] . '/index', ['navid' => $v['id']]);
            } else {
                $dd['url'] = $this->request->domain() . url($v['model'] . '/detailed', ['id' => $v['id'], 'navid' => $v['cid']]);
            }
            $dd['time'] = date('Y-m-d H:i:s', $v['create_time']);

            $site->AddItem($dd, 1);
        }
        $site->SaveToFile('sitemap.xml');
        $this->redirect($this->request->server('HTTP_REFERER'));
    }
}
